<?php

namespace Common\Model;

use Think\Model;

class TransRecordModel extends Model {

    protected $_validate = array(/* array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间]) */
        array('couponID','require','体验券ID为空'),
        array('fromID','require','原持有人ID为空'),
        array('toID','require','现持有人ID为空'),
    );  // 自动验证定义
    
    protected $_auto = array(/* array(完成字段1,完成规则,[完成条件,附加规则]) */
        array('addTime', 'time', 1, 'function')
    );  // 自动完成定义

    /**
     * 添加
     */
    public function addTransRecord($data = '') {
        $rt = false;
        if ($this->create($data)) {
            $rt = $this->add();
        }
        return $rt;
    }

    /**
     *  获取转让记录列表
     */
    public function getTransRecordList($couponID, $where = array()) {
        
        if (!empty($couponID)) {
            $where['couponID'] = $couponID;
        }

        $recordList = $this->where($where)->select();
//        if($recordList) {
//            
//        }

        return $recordList;
    }

    /**
     * 获得列表（带基本查询）
     */
    public function getServiceTypeList($pageNo = 1, $pageSize = 15, $where = array(), $order = array(), $field = "*") {
        $rt = $this->field($field)->where($where)->page("$pageNo,$pageSize")->order($order)->select();
        return $rt;
    }

    public function getServiceTypeLength($where = array()) {
        return $this->where($where)->count();
    }

}

?>